﻿
using Microsoft.Win32;



Console.WriteLine("当前所有网络列表:");

string registryPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\Profiles";
// 打开注册表中的指定键
RegistryKey? profilesKey = Registry.LocalMachine.OpenSubKey(registryPath);
if (profilesKey == null)
{
    Console.WriteLine("无法打开注册表键！请使用管理员权限打开！");
    Console.ReadLine();
    return;
}

// 获取子目录名称
int count = 0;
string[] networkList = profilesKey.GetSubKeyNames();
foreach (string subKeyName in networkList)
{
    RegistryKey? networkKey = Registry.LocalMachine.OpenSubKey(Path.Combine(registryPath, subKeyName));
    // 获取注册表值
    string? value = networkKey?.GetValue("ProfileName")?.ToString();
    // 输出值数据
    Console.WriteLine($"{count++}.网络名称: {value}");
}
label1:
Console.Write("请输入要清除的网络：");
string? input = Console.ReadLine();
int deleteIndex = -1;
if (!string.IsNullOrEmpty(input))
    deleteIndex = int.Parse(input);
if (deleteIndex >= networkList.Length)
{
    Console.Write("请输入正确的网络编号：");
}
else if (deleteIndex >= 0)
{
    Console.WriteLine($"你将要清除网络{networkList[deleteIndex]},此操作不可逆，是否继续？（Y/N）");
    input = Console.ReadLine();
    if (input?.ToLower() == "y")
    {
        //删除注册表
        Registry.LocalMachine.DeleteSubKeyTree(Path.Combine(registryPath, networkList[deleteIndex]));
    }
}
goto label1;



